home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / RemoteObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.4 KB  |  118 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataInputStream;
  4. import java.io.DataOutputStream;
  5. import java.io.EOFException;
  6. import java.io.IOException;
  7. import java.util.Vector;
  8. import symjava.sql.SQLException;
  9.  
  10. public class RemoteObject extends Requester {
  11.    Vector _params;
  12.    String _className;
  13.    ServerList _results;
  14.    NetString _reqStr;
  15.    int _ctorID;
  16.    int _mode;
  17.    int _objectID;
  18.    boolean _disabled = true;
  19.  
  20.    public RemoteObject(String className, int objectID, ClientSession sess) {
  21.       super(sess);
  22.       this._disabled = false;
  23.       this.setObject(className, objectID);
  24.    }
  25.  
  26.    public void setObject(String className, int objectID) {
  27.       this._className = new String(className);
  28.       this._objectID = objectID;
  29.    }
  30.  
  31.    public void disable() {
  32.       this._disabled = true;
  33.    }
  34.  
  35.    protected void readResults(DataInputStream in) throws SQLException, IOException, ErrorException {
  36.       if (this._mode != 2) {
  37.          ServerObject obj = (ServerObject)NetClass.getNextObject(in);
  38.          if (this._mode == 0 && obj.getType() == 51) {
  39.             try {
  40.                this._ctorID = ((NetData)obj).getInt();
  41.             } catch (EOFException var3) {
  42.                throw new IOException("Invalid Server Object returned.");
  43.             }
  44.          } else if (this._mode == 1 && obj.getType() == 54) {
  45.             this._results = (ServerList)obj;
  46.          } else {
  47.             ((Requester)this).onObjectError(obj);
  48.          }
  49.       }
  50.    }
  51.  
  52.    protected void writeRequest(DataOutputStream out) throws IOException {
  53.       this._reqStr.write(out);
  54.  
  55.       for(int i = 0; i < this._params.size(); ++i) {
  56.          ServerObject s = (ServerObject)this._params.elementAt(i);
  57.          s.write(out);
  58.       }
  59.  
  60.    }
  61.  
  62.    public synchronized int invokeConstructor(int ctor_sel, Vector params) throws SQLException {
  63.       if (this._disabled) {
  64.          throw new SQLException("Error: Remote Object closed");
  65.       } else {
  66.          this._mode = 0;
  67.          this._reqStr = new NetString("proxy" + super._reqDelim + "new" + super._reqDelim + this._className + super._reqDelim + ctor_sel);
  68.          this._params = params;
  69.          ((Requester)this).execute();
  70.          return this._ctorID;
  71.       }
  72.    }
  73.  
  74.    public Vector invokeMethod(int mid) throws SQLException {
  75.       return this.invokeMethod(mid, new Vector());
  76.    }
  77.  
  78.    public Vector invokeMethod(int mid, int data) throws SQLException {
  79.       Vector params = new Vector();
  80.       params.addElement(new Param(0, data));
  81.       return this.invokeMethod(mid, params);
  82.    }
  83.  
  84.    public Vector invokeMethod(int mid, String data) throws SQLException {
  85.       Vector params = new Vector();
  86.       params.addElement(new TextParam(0, data));
  87.       return this.invokeMethod(mid, params);
  88.    }
  89.  
  90.    public Vector invokeMethod(int mid, boolean data) throws SQLException {
  91.       Vector params = new Vector();
  92.       params.addElement(new Param(0, data));
  93.       return this.invokeMethod(mid, params);
  94.    }
  95.  
  96.    public synchronized Vector invokeMethod(int mid, Vector params) throws SQLException {
  97.       if (this._disabled) {
  98.          throw new SQLException("Error: Remote Object closed");
  99.       } else {
  100.          this._mode = 1;
  101.          this._reqStr = new NetString("proxy" + super._reqDelim + "invoke" + super._reqDelim + this._objectID + super._reqDelim + mid);
  102.          this._params = params;
  103.          ((Requester)this).execute();
  104.          return this._results.getObjVector();
  105.       }
  106.    }
  107.  
  108.    public synchronized void invokeDestructor(int oid) throws SQLException {
  109.       if (this._disabled) {
  110.          throw new SQLException("Error: Remote Object closed");
  111.       } else {
  112.          this._mode = 2;
  113.          this._reqStr = new NetString("proxy" + super._reqDelim + "delete" + super._reqDelim + oid);
  114.          ((Requester)this).execute();
  115.       }
  116.    }
  117. }
  118.